<?php
include_once('code_parents.php');
class code_home extends code_parents {
	private $CI;
	private $baseUrl;
	function __construct() {
		$CI = & get_instance ();
		$this->CI = $CI;
		$CI->load->helper ( 'url' );
		$this->baseUrl = $CI->config->base_url ();
	}
	
	/**
	 * 说明下一这里为什么要写 一个 status 这个参数我们要通过后台判断是否本人的 判断如何显示
	 * Enter description here ...
	 * @param unknown_type $data
	 * @param unknown_type $satus
	 */
	function leftDiv($data, $satus = 0) {
		$userId 	= $this->CI->session->userdata ( "userId" );
		$nickName 	= $this->CI->session->userdata ( "nickName" );
		$userIcon 	= $this->getUserIcon($data ['userBigIcon']);
		$para 	  	= $this->baseUrl . "index.php/friendsreferral/addFriend";
		$accepterId = $data ['userId'];
		//?userId=$userId&accepterId=" . $data ["userId"] . "&perserteeName=$nickName&perserteeId=$userId";
		$divCode = "<script type='text/javascript'>";
		$divCode .= "$(document).ready(function () {";
		$divCode .= "$('#home_add_friend').click(function(){";
		$divCode .= "$.get('$para',{userId:'$userId',accepterId:'$accepterId',perserteeName:'$nickName',perserteeId:'$userId'},function(data){";
		$divCode .= "$('#dialogDiv').wjDialog({url:'$this->baseUrl/index.php/',content:data});";
		$divCode .= "});";
		$divCode .= "});";
		$divCode .= "});";
		$divCode .= "</script>";
		$divCode .= "<div class='content'>";
		$divCode .= "<div class='tdzy_lf'>";
		$divCode .= "<div class='tdzy_lfd1'>";
		$divCode .= "<img src='$userIcon' width='192' height='192' class='grzy_img'>";
		$divCode .= "<h3>$nickName<img src='$this->baseUrl/assets/images/grzy_12.gif' width='14' height='13'><strong></strong></h3>";
		$divCode .= $satus == 0 ? "<p class='grzy_p1'><a style='cursor:pointer'  id='home_add_friend'>+ 加为好友</a><a href='$para'><img src='$this->baseUrl/assets/images/grzy_02.gif' width='14' height='11'>&nbsp;&nbsp;发信</a></p>" : "";
		$divCode .= "</div>";
		$divCode .= "<div class='bmlf_lf1'>";
		$divCode .= "<ul>";
		$divCode .= "<li id='home_id_dynamic_yearbook' class='lf1_hover1'><a href='#'><strong>年鉴</strong></a></li>";
		$divCode .= "<li id='home_id_dynamic_photowall' class='lf1_hover2'><a href='#'><strong>照片墙</strong></a></li>";
		$divCode .= "<li id='home_id_dynamic_zw' class='lf1_hover4'><a href='#'><strong>知我</strong></a></li>";
		$divCode .= "<li id='home_id_dynamic_team' class='lf1_hover8'><a href='#'><strong>所在团队</strong></a></li>";
		$divCode .= "</ul>";
		$divCode .= "</div><!-- end bmlf_lf1 -->";
		$divCode .= "</div><!-- end tdzy_lf -->";
		
		return array ("leftDiv" => $divCode );
	}
	function topDiv($status = 0) {
		$dynamicTip = $status == 0 ? "动态" : "我的最近动态";
		$divCode = "<div class='tdzy_rg'>";
		$divCode .= "<div class='grzx_top_bg'>";
		$divCode .= "<!--开发人员需注意，这块当用户选中某一项，li上要加on类名，需用js实现选中哪个分别加on，样式都已写好-->";
		$divCode .= "<ul>";
		$divCode .= "<li id='home_id_dynamic_all'><div href='#' class='pidli_01'>$dynamicTip</div></li>";
		$divCode .= "<li id='home_id_dynamic_text'><div href='#' class='pidli_02'>文字</div></li>";
		$divCode .= "<li id='home_id_dynamic_link'><div href='#' class='pidli_03'>链接</div></li>";
		$divCode .= "<li id='home_id_dynamic_image'><div href='#' class='pidli_04'>图片</div></li>";
		$divCode .= "<li id='home_id_dynamic_video'><div href='#' class='pidli_05'>视频</div></li>";
		$divCode .= "</ul>";
		$divCode .= "</div>";
		$divCode .= "</div>";
		
		return $divCode;
	}
	
	function rightDiv($data, $state) {
		$divCode = "";
		if (! empty ( $data )) {
			foreach ( $data as $row ) {
				extract ( $row );
				$arrayImg = explode ( ",", $imgSrc );
				$strImg = "";
				foreach ( $arrayImg as $val ) {
					if (! empty ( $val ))
						$strImg .= "<img src='$val' width='109' height='109' />&nbsp;&nbsp;";
				}
				
				$purview = $state == 1 ? "<a href='#'>删除</a><a href='#'>编辑</a><a href='#'>回应</a>" : "<a href='#'>回应</a>";
				$divCode .= "<div class='tdzy_rgd2'>";
				$divCode .= "<div class='rgd2_d1'></div>";
				$divCode .= "<div class='rgd2_d2 grzy_d2'>";
				$divCode .= "<h3><span>-</span>$title</h3>";
				$divCode .= (($type == "video") || empty ( $strImg )) ? "" : "<div class='grzy_d21'>$strImg</div>";
				$divCode .= "<div class='grzy_d22'>";
				$divCode .= "<p class='gr_p1'>发表于：$createTime $description</p>";
				$divCode .= "<p class='gr_p1'>威客，一般指那些通过互联网把自己的知识、智慧、经验、技能转换成实际收益的人。这一概念最早于2005年出现，后来经过媒体的宣传报道，威客群体不断发展壮大，国内人数如今已经超过3000万。</p>";
				$divCode .= "<p class='gr_p1'>而且由于威客与网络息息相关，工作形式灵活自由，所以备受年轻人的青睐，更有机构在去年将威客评为“90后”最为推崇的十大时尚职业之一。有专家以及资深威客提醒，虽然现在专职做威客的人越来越多，但兼职仍然是主流。专职做威客挑战较大，需谨慎。兼职做威客...</p>";
				$divCode .= "<p class='gr_p2'><span></span><a href='$this->getBaseUrl(user_home/showData/$userId/1/5/$type//true)'>阅读全部</a></p>";
				$divCode .= "</div>";
				$divCode .= "</div>";
				$divCode .= "<div class='rgd2_d3'></div>";
				$divCode .= "</div><!-- end tdzy_rgd2 -->";
			}
		}
		return $divCode;
	}
	function homeDynamicDiv($data, $state,$isDetail=0) {
		$divCode 		= "";
		$dynamicType	="";
		if (! empty ( $data )) {
			foreach ( $data as $row ) {
				$row = $this->userDynamicOperation ( $row );
				extract ( $row );
				$arrayImg = explode ( ",", $imgSrc );
				$strImg = "";
				foreach ( $arrayImg as $val ) {
					if (! empty ( $val ))
						$strImg .= "<img src='$val' width='109' height='109' />&nbsp;&nbsp;";
				}
				$dynamicType = $type;
				$path		 = $this->getBaseUrl("index.php/user_home/showData/$userId/1/5/$type/1/-1/$id");
				$purview 	 = ($state == 1 ? "<a style='cursor:pointer' class='eventClass' deleId='$id'>删除</a>" : "") . "<a class='dynamic_reply' title='$id' style='cursor:pointer;'>回应</a>";
				$divCode 	.= "<div class='tdzy_rgd2'>";
				$divCode 	.= "<div class='rgd2_d1'></div>";
				$divCode 	.= "<div class='rgd2_d2 grzy_d2'>";
				$divCode 	.= "<h3><span>-</span>$title</h3>";
				$divCode 	.= (($type == "video") || empty ( $strImg )) ? "" : "<div class='grzy_d21'>$strImg</div>";
				$divCode 	.= "<div class='grzy_d22'>";
				$divCode 	.= "<p class='gr_p1'>发表于：$createTime $description</p>";
				$divCode 	.= $content;
				$divCode 	.= $this->sendComments($id);
				$divCode 	.= "<p class='gr_p2'><span>$purview</span><a deleId='$path' class='viewDetail'  style='cursor:pointer;'>阅读全部</a></p>";
				$divCode 	.= "</div>";
				$divCode 	.= "</div>";
				$divCode 	.= "<div class='rgd2_d3'></div>";
				$divCode 	.= "</div><!-- end tdzy_rgd2 -->";
			}
		}
		return  $divCode.(($isDetail!=0 && empty($data) == false)?$this->getRreplayDivs($isDetail,'dynamic'):"");
	}
	function sendComments($id) {
		$divCode = "<div style='width:100%' class='div_display' id='div_display_$id'>";
		$divCode .= "<form id='replyForm' method='post' action='$this->baseUrl/index.php/team/replayUsersDynamic'>";
		$divCode .= "<textarea name='reply_content' id='reply_content_$id' rows='7' style='width:630px;'></textarea>";
		$divCode .= "<input type='hidden' name='dynamicId' id='dynamicId_$id' value='$id'/>";
		$divCode .= "<p class='gr_p1'><input type='button' class='send_btn' replyId='$id' title='发送' style='float:right;margin-top:10px;' /></p>";
		$divCode .= "</form>";
		$divCode .= "</div>";
		return $divCode;
	}
	function sendBindClick() {
		$divCode = "<script type='text/javascript'>";
		$divCode .= "$(function() {";

		$divCode .= "});";
		$divCode .= "</script>";
		return $divCode;
	}
	function userDynamicOperation($data) {
		extract ( $data );
		$title = "";
		$divCode = "";
		if ($type == "image") {
			$title = "$nickName 图片";
			$divCode = empty ( $content ) ? "" : "<p class='gr_p1'>$content</p>";
		} elseif ($type == "video") {
			$title = "$nickName 视频 :" . $title;
			$divCode = "<p class='gr_p1'> $content";
			/*
			$divCode .= "<div id='eventWindow'>";
			$divCode .= "<script type='text/javascript'>";
			$divCode .= "$(document).ready(function () {";
			$divCode .= "$('#eventWindow').wjPlayVideo({video:'$content',image:'$imgSrc',url:'$this->baseUrl'});";
			$divCode .= "});";
			$divCode .= "</script>";
			$divCode .= "</div>";
			*/
			
			$divCode .= "</p>";
			$divCode .= empty ( $description ) ? "" : "<p class='gr_p1'>$description</p>";
		} elseif ($type == "link") {
			$title = "$nickName 链接 ";
			$divCode = "<p class='gr_p1'>$content</p>";
			$divCode .= empty ( $description ) ? "" : "<p class='gr_p1'>$description</p>";
		} else {
			$title = "$nickName 说说 ";
			$divCode = empty ( $content ) ? "" : "<p class='gr_p1'>$content</p>";
		}
		$data ['title'] = $title;
		$data ['content'] = $divCode;
		return $data;
	}

}
